<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


include "header.php";
include "/library/product.php";

if(isset($_GET['add'])){
    ck_empty($_GET);
   
    addProduct($_GET);
    //header('location: product.php');
}
if(isset($_GET['editform'])){
    $editData = query_one($_GET['id']);
    $editType = query_one_type($_GET['id']);
    //header('location: customer_type.php');
}
if(isset($_GET['edit'])){
    editProduct($_GET);
    //header('location: product.php');
}

?>
<head>
<script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
<link type="text/css" href="css/Aristo/jquery-ui-1.8.7.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-ui-1.8.11.custom.min.js"></script>
<script type="text/javascript" src="js/product_add.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
   <?php while ($print = mysql_fetch_array($editType)){ ?>
        $(function (){
            $('#table_type').show();
        
        $count++;
        var content = $('#prototype').clone();
        content.find('tr').attr("id", $count);
        content.find('a').attr("onClick", "delType('"+$count+"')");
        $("#addType").append(content.html());

        $('tr#'+$count+' input[name="type_name[]"]').val("<?php echo $print['name']; ?>");
        $('tr#'+$count+' input[name="type_id[]"]').val("<?php echo $print['id']; ?>");
        $('tr#'+$count+' input[name="type_nameunit[]"]').val("<?php echo $print['nameunit']; ?>");
        $('tr#'+$count+' input[name="type_ratio[]"]').val("<?php echo $print['ratio']; ?>");
        $('tr#'+$count+' input[name="type_asset[]"]').val("<?php echo $print['asset']; ?>");
        $('tr#'+$count+' input[name="type_buyprice[]"]').val("<?php echo $print['buyprice']; ?>");
        
        });
    <?php  } ?>

    });



</script>
</head>
<div id="product" align="center" width="100%">
    <form action="product_add.php" method="get">
    <table  id="tableSmall">
        <tr>
            <th>รหัสสินค้า</th>
            <td id="otherdetail"><input type="text" name="product_id" value="<? if(!empty($editData['product_id'])) echo $editData['product_id']; ?>"></td>
        </tr>
        <tr>
            <th >ชื่อสินค้า</th>
            <td id="otherdetail"><input type="text" name="name" value="<? if(!empty($editData['name'])) echo $editData['name']; ?>"></td>
        </tr>
        
        <div id="product_type">
            
            <table id="table_type">
                
                <tr>
                    <th>ชื่อประเภท</th>
                    <th>ชื่อหน่วย</th>
                     <th >อัตราต่อหน่วย</th>
                     <th>ราคาทุน</th>
                     <th>ราคาขาย</th>
                     <th></th>
                    
                </tr>
                <tbody id="prototype" >

                <tr >
                        <td id="name" ><input type="text" id="name" name="type_name[]" >
                        <td id="otherdetail" ><input type="text" name="type_nameunit[]" ><input type="hidden" name="type_id[]" ></td>
                        <td id="otherdetail"><input type="text" name="type_ratio[]" ></td>
                        <td id="otherdetail"><input type="text" name="type_asset[]" ></td>
                        <td id="otherdetail"><input type="text" name="type_buyprice[]" ></td>
                        <td id="otherdetail"><a href="#" ><input type="button" name="add" value=" ลบ "></a></td>
                </tr>
                </tbody>

                <tbody id="addType">
                    
                </tbody>
               
               
            </table>
             <div id="button_addtype">
                     <input type="button" value="เพิ่มประเภท">
                </div>
         </div>
       
       
    </table>
     <div id="addCustomer_type">
        <?php
            if(isset($_GET['editform'])){ ?>
        
        
        <input type="hidden" name="id" value="<?=$_GET['id'];?>">
        <input type="submit" name="edit" value=" แก้ไข ">

           <?php }else { ?>
      
        
        <input type="submit" name="add" value=" เพิ่ม ">
        <?php } ?>
</div>
    </form>

    <p>
    </p>

</div>
